package com.vcredit.creditcat.service;

import java.io.File;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.vcredit.creditcat.enumtype.DateStyleEnum;
import com.vcredit.creditcat.framework.util.ConstantsUtil;
import com.vcredit.creditcat.framework.util.DateUtil;

/**
 * 
 * @author chengxin
 *
 */
public class BaseService {
	/**
	 * 生成文件目录 linux路径 chengxin 创建
	 * 
	 * @param littype
	 * @param excelversion
	 * @return
	 * @throws Exception
	 */
	protected String createfileName(String excelName, String excelversion) throws Exception {

		String files = excelName + DateUtil.DateToString(new Date(), DateStyleEnum.yyyyMMddHHmmssSSS) + excelversion;
		return files;
	}

	/**
	 * 生成文件目录 windows chengxin 创建
	 * 
	 * @param request
	 * @param littype
	 * @param excelversion
	 * @return windows路径
	 * @throws Exception
	 */
	protected String filePathForWin(HttpServletRequest request, String littype, String excelversion) throws Exception {

		// String files =littype + DateUtil.DateToString(new Date(),
		// DateStyle.yyyyMMddHHmmssSSS) + excelversion;
		String files = request.getSession().getServletContext().getRealPath("/") + "\\" + "excel" + "\\" + littype
				+ DateUtil.DateToString(new Date(), DateStyleEnum.yyyyMMddHHmmssSSS) + excelversion;
		return files;
	}

	/**
	 * 生成文件目录 windows chengxin 创建
	 * 
	 * @param request
	 * @param littype
	 * @param excelversion
	 * @return windows路径
	 * @throws Exception
	 */
	protected String fileImgPathForWin(HttpServletRequest request) throws Exception {

		// String files =littype + DateUtil.DateToString(new Date(),
		// DateStyle.yyyyMMddHHmmssSSS) + excelversion;
		String files = request.getSession().getServletContext().getRealPath("/") + "\\" + "excel" + "\\"
				+ DateUtil.DateToString(new Date(), DateStyleEnum.YYYY_MM_DD) + "\\";
		File folder = new File(files);
		if (!folder.exists()) {
			folder.mkdirs();
		}
		return files;
	}

	/**
	 * 生成文件目录 windows chengxin 创建
	 * 
	 * @param request
	 * @param littype
	 * @param excelversion
	 * @return windows路径
	 * @throws Exception
	 */
	protected String fileImgPathForLinuxMulu(HttpServletRequest request) throws Exception {

		// String files =littype + DateUtil.DateToString(new Date(),
		// DateStyle.yyyyMMddHHmmssSSS) + excelversion;
		String files = ConstantsUtil.ExcelPath + DateUtil.DateToString(new Date(), DateStyleEnum.YYYY_MM_DD) + "/";

		File folder = new File(files);
		if (!folder.exists()) {
			folder.mkdirs();
		}
		return files;
	}
}
